package commandes;

import java.util.*;

import javax.servlet.*;
import javax.servlet.http.*;
import beans.*;
import bdd.*;

// Cette cde recupere l'ensemble des clients:
//
public class CommandePropLog implements Commande {
  private String next;

  public CommandePropLog(String next) {
        this.next = next;
  }

  public String execute(HttpServletRequest req) throws Exception {
	  
	DBS db = DBS.getInstance();
	List<Proprietaire> props = db.getDB_Proprietaire().getProprietaires();
	if(req.getParameter("listProp")!=null){
		
		int idProprio = Integer.parseInt(req.getParameter("listProp"));
		Proprietaire proprio = db.getDB_Proprietaire().getProprietaire(idProprio);
		String nom = proprio.getNom();
		String prenom = proprio.getPrenom();
		
		List<Logement> logs = db.getDB_Logement().getLogements("select * from Logement,Proprietaire "
															  +"where Logement.idproprio = Proprietaire.idproprio "
															  +"and nom='"+nom+"' and prenom='"+prenom+"';");
		System.out.println(logs);
		req.setAttribute("logements", logs);
		
	}
	else{
	
		List<Logement> logs = new ArrayList<Logement>();
		req.setAttribute("logements", logs);
	}
	req.setAttribute("proprietaires", props);
	return next;
  }
}
